(function(w, d) {
	var utils = {
		parse : function(temlstr, jsonarr, process) {
			var reg = /#\w+(\.\w+)*({\d+})?#/gi;
			if (!jsonarr) { 
				return temlstr.replace(reg, '');
			}
			var keys = temlstr.match(reg);
			if (!keys) { return temlstr; }
			if (typeof jsonarr != 'array' && 
					!(jsonarr instanceof Array)) { 
				jsonarr = [ jsonarr ]; 
			}
			var stringbuilder = '', obj = null;
			for (var i = 0; i < jsonarr.length; i ++) { 
				obj = temlstr;
				for (var j = 0; j < keys.length; j ++) { 
					var idx = keys[j].match(/{\d+}/), end; 
					if (idx) { 
						end = keys[j].indexOf(idx[0]); 
						idx = idx[0].match(/\d+/)[0]; 
					} else { 
						end = keys[j].length - 1; 
					} 
					var key = keys[j].substring(1, end), 
						val = jsonarr[i];
					var arr = key.split('\.'); 
					for (var k = 1; k < arr.length; k ++) { 
						if (arr[k] && val) { 
							val = val[arr[k]]; 
							if (typeof process == 'function') { 
								val = process(key, val, idx); 
							} 
							if (typeof val == 'array' ||
									val instanceof Array) { 
								obj = utils.multi(
									obj, key, val, process
								); 
							} 
						} 
					} 
					key = !idx ? key : (key + '{' + idx + '}'); 
					val = (val != null) ? val : '';
					obj = obj.split('#' + key + '#').join(val); 
				} 
				stringbuilder += obj; 
			} 
			return stringbuilder; 
		},
		multi : function(cell, dest, jsonarr, process) { 
			var ID = dest.replace(/\./gi, '_') + '_template';
			var string = document.getElementById(ID).innerHTML;
			var result = utils.parse(string, jsonarr, process); 
			return cell.split('#' + dest + '#').join(result); 
		},
		title : function(title) {
			if (title) {
				(function(d) {
					var _iframe_ = d.createElement('iframe');
					_iframe_.style.border = null;
					_iframe_.style.width = '0px';
					_iframe_.style.height = '0px';
					_iframe_.src = '/favicon.ico';
					var _body = d.getElementsByTagName('body');
					_iframe_.onload = function() {
						_settimeout(function() {
							_body[0].removeChild((_iframe_));
						}, 0);
					};
					var t = d.getElementsByTagName('title')[0];
					t.innerHTML = title;
					_body[0].appendChild(_iframe_);
				})(document);
			}
		}
	};
	if (!w.leopard) { w.leopard = {}; };
	w.leopard.parse = utils.parse;
	w.leopard.title = utils.title;
})(window, document);